package com.songtai.action.admin.general;

import java.util.Date;
import java.util.List;

import org.apache.commons.beanutils.BeanUtils;

import com.songtai.action.SongtaiActionSupport;
import com.songtai.po.PhotoObj;
import com.songtai.po.PublicObj;
import com.songtai.service.ImageService;
import com.songtai.service.PublicObjService;

/**
 * 公共文字
 * 
 * @author lx
 * 
 */
public class PublicObjAction extends SongtaiActionSupport {

	private static final long serialVersionUID = 1335235791282165778L;

	private PublicObjService publicObjService;

	private String nid;

	private PublicObj pub;

	private PublicObj pub2;

	private List<PublicObj> qq;

	private List<PublicObj> objList;

	private String url;

	private String id;

	private String ids;

	private Long slider_id = 2L;
	private List<PhotoObj> sliderList;
	private ImageService imageService;

	/**
	 * 获取文字信息
	 * 
	 * @return
	 * @throws Exception
	 */
	public String getObj() throws Exception {
		pub = publicObjService.getObjByNid(nid);

		return SUCCESS;
	}

	/**
	 * 添加文字信息
	 * 
	 * @return
	 * @throws Exception
	 */
	public String addPublicObj() throws Exception {
		url = "getObj.htm?nid=" + pub.getNid();
		pub.setRecordTime(new Date());
		publicObjService.addObj(pub);
		return SUCCESS;
	}

	/**
	 * 添加联系信息
	 * 
	 * @return
	 * @throws Exception
	 */
	public String addAboutObj() throws Exception {
		url = "getAbout.htm?nid=" + pub.getNid();
		pub.setRecordTime(new Date());
		publicObjService.addObj(pub);
		if (pub.getNid().equals("23")) {
			url = "getAbout.htm?nid=" + pub.getNid();
		}
		return SUCCESS;
	}

	/**
	 * 获取联系信息
	 * 
	 * @return
	 * @throws Exception
	 */
	public String getAbout() throws Exception {
		objList = publicObjService.getObjsByNid(nid);
		if (nid.equals("23")) {
			return "qq";
		}
		return SUCCESS;
	}

	/**
	 * 联系信息跳转修改页
	 * 
	 * @return
	 * @throws Exception
	 */
	public String toUpdateAboutObj() throws Exception {
		pub = publicObjService.getObj(id);
		if (null != nid) {
			if (nid.equals("23")) {
				return "qqupdate";
			}
		}
		return SUCCESS;
	}

	/**
	 * 联系信息修改
	 * 
	 * @return
	 * @throws Exception
	 */
	public String updateAboutObj() throws Exception {
		url = "getAbout.htm?nid=" + nid;
		PublicObj pubTemp = publicObjService.getObj(pub.getId());
		BeanUtils.copyProperties(pubTemp, pub);
		pubTemp.setRecordTime(new Date());
		pubTemp.setNid(Long.parseLong(nid));
		publicObjService.updateObj(pubTemp);
		return SUCCESS;
	}

	/**
	 * 删除联系信息
	 * 
	 * @return
	 * @throws Exception
	 */
	public String delAboutObjs() throws Exception {
		url = "getAbout.htm?nid=" + nid;
		publicObjService.delObjs(ids, nid);
		return SUCCESS;
	}

	/**
	 * 删除
	 * 
	 * @return
	 * @throws Exception
	 */
	public String delPublicObj() throws Exception {
		url = "getObj.htm?nid=" + nid;
		PublicObj obj = publicObjService.getObj(id);
		publicObjService.delPublicObjById(obj);
		return SUCCESS;
	}

	/**
	 * 跳转修改页
	 * 
	 * @return
	 * @throws Exception
	 */
	public String toUpdatePublicObj() throws Exception {
		pub = publicObjService.getObj(id);
		return SUCCESS;
	}

	/**
	 * 修改
	 * 
	 * @return
	 * @throws Exception
	 */
	public String updatePublicObj() throws Exception {
		url = "getObj.htm?nid=" + nid;
		PublicObj pubTemp = publicObjService.getObj(id);
		String id = pubTemp.getId();
		BeanUtils.copyProperties(pubTemp, pub);
		pubTemp.setId(id);
		pubTemp.setNid(Long.parseLong(nid));
		pubTemp.setRecordTime(new Date());
		publicObjService.updateObj(pubTemp);
		return SUCCESS;
	}

	/**
	 * 跳转到WEB QQ修改页
	 * 
	 * @return
	 * @throws Exception
	 */
	public String toUpdateQqObj() throws Exception {
		pub = publicObjService.getObj(id);
		return SUCCESS;
	}

	/**
	 * 前台获取信息
	 * 
	 * @return
	 * @throws Exception
	 */
	public String frontObj() throws Exception {

		if (nid.equals("5")) {
			qq = publicObjService.getObjsByNid("23");
			pub = publicObjService.getObjByNid(nid);
			pub2 = publicObjService.getObjByNid("21");

			sliderList = imageService.getImageByNodeid(slider_id, 10,
					PhotoObj.TYPE_SLIDER);
			return "kno";
		}
		if (nid.equals("18")) {
			qq = publicObjService.getObjsByNid("23");
			pub = publicObjService.getObjByNid(nid);
			pub2 = publicObjService.getObjByNid("21");
			sliderList = imageService.getImageByNodeid(slider_id, 10,
					PhotoObj.TYPE_SLIDER);
			return "process";
		}
		if (nid.equals("19")) {
			qq = publicObjService.getObjsByNid("23");
			pub = publicObjService.getObjByNid(nid);
			pub2 = publicObjService.getObjByNid("21");
			sliderList = imageService.getImageByNodeid(slider_id, 10,
					PhotoObj.TYPE_SLIDER);
			return "service";
		}
		if (nid.equals("21")) {
			pub = publicObjService.getObjByNid(nid);
			return "service";
		}
		if (nid.equals("22")) {
			qq = publicObjService.getObjsByNid("23");
			objList = publicObjService.getObjsByNid(nid);
			pub = publicObjService.getObjByNid("21");
			sliderList = imageService.getImageByNodeid(slider_id, 10,
					PhotoObj.TYPE_SLIDER);
			return "about";
		}

		return "kno";

	}

	public void setPublicObjService(PublicObjService publicObjService) {
		this.publicObjService = publicObjService;
	}

	public String getNid() {
		return nid;
	}

	public void setNid(String nid) {
		this.nid = nid;
	}

	public PublicObj getPub() {
		return pub;
	}

	public void setPub(PublicObj pub) {
		this.pub = pub;
	}

	public String getUrl() {
		return url;
	}

	public void setUrl(String url) {
		this.url = url;
	}

	public String getId() {
		return id;
	}

	public void setId(String id) {
		this.id = id;
	}

	public List<PublicObj> getObjList() {
		return objList;
	}

	public void setObjList(List<PublicObj> objList) {
		this.objList = objList;
	}

	public String getIds() {
		return ids;
	}

	public void setIds(String ids) {
		this.ids = ids;
	}

	public PublicObj getPub2() {
		return pub2;
	}

	public void setPub2(PublicObj pub2) {
		this.pub2 = pub2;
	}

	public List<PhotoObj> getSliderList() {
		return sliderList;
	}

	public void setSliderList(List<PhotoObj> sliderList) {
		this.sliderList = sliderList;
	}

	public void setImageService(ImageService imageService) {
		this.imageService = imageService;
	}

	public List<PublicObj> getQq() {
		return qq;
	}

	public void setQq(List<PublicObj> qq) {
		this.qq = qq;
	}

}
